Clear Text Field on Focus using JavaScript
Here is a JavaScript code that will clear a text field when it gets focus. <input type="text" onfocus="if(this.value != '') { this.value = ''; }" value="Enter your Name" /> More JavaScript Snippets
Here is a JavaScript code that will clear a text field when it gets focus. <input type="text" onfocus="if(this.value != '') { this.value = ''; }" value="Enter your Name" /> More JavaScript Snippets
Here is how you can remove all empty spaces from a string using JavaScript. var str = "T u toria l s Pa n el. co m"; var newStr = str.replace(/\s+/g, ''); alert(newStr); More JavaScript Snippets
An easy way to shuffle an array using JavaScript: var arr = [1,2,3,4,5]; var newArr; newArr = arr.sort(function() { return 0.5 - Math.random() }); alert(newArr); Related Snippets
To remove the last character of a string, using Javascript: var input = 'butterflyy'; var result = input.substring(0, input.length-1); alert(result); Happy Coding!! Related Snippets
A code snippet to take all number off a string using JavaScript <script> var MyString = "Tutorials1P2anel3"; stringOnly = MyString.replace(/[0-9]/g, ''); alert(stringOnly); </script> You can replace the alert with anything else that would fit your coding needs. Related Snippets
A Javascript function to check email validation. Returns boolean. function ValidateEmail(email) { var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; if (!reg.test(email)) return false; return true; } Happy Coding! Related Snippets
The snippet below selects a random item from an array and show it in an alert box using Javascript. <script> var arr = [ "ASP.NET", "C", "C++", "C#", "Java", "JavaScript", "MVC CORE", "VB.NET" ]; var random = arr[Math.floor(Math.random()*arr.length)]; alert(random) </script> Happy Coding! Related Snippets